type executorType = (resolve: (result?: any) => void, reject: (reject?: any) => void) => void

enum PromiseStatus {
    PROMISE_STATUS_PENDING,
    PROMISE_STATUS_FULFTLLED,
    PROMISE_STATUS_REJECTED
}

class YYpromise {
    private status: PromiseStatus = PromiseStatus.PROMISE_STATUS_PENDING
    private value: any
    private reason: any
    private onfulfilled
    private onrejected


    constructor(executor: executorType) {

        const resolve = <S>(result: S) => {
            if (this.status == PromiseStatus.PROMISE_STATUS_PENDING) {
                this.status = PromiseStatus.PROMISE_STATUS_FULFTLLED
                this.value = result
            }
        }

        const reject = <S>(reject: S) => {
            if (this.status == PromiseStatus.PROMISE_STATUS_PENDING) {
                this.status = PromiseStatus.PROMISE_STATUS_REJECTED
                this.reason = reject
            }
        }
        executor(resolve, reject)
    }


    then<T,E> = (onfulfilled: (res:T) => T, onrejected: (E) => void) => {
        this.onfulfilled = onfulfilled
        this.onrejected = onrejected
    }

}

const promise = new YYpromise((resolve, reject) => {
    resolve('21312')
    reject(123)
}).then((res) => {

}, (error) => { })

export { }